import React, { Component } from 'react'
import {
    View,
    Text,
    Image,
    TouchableOpacity,
} from 'react-native';
import { M_position_content_3 as styles } from '../../../../styles';     //引入样式完毕
import Nature from '../../../util/Nature';
import {common_url} from "../../../util/fetch";

export default class Gongsi extends Component {
    constructor(props) {
        super(props);
    }
    render() {
        return (
            <TouchableOpacity style={styles.mar_m}
                activeOpacity={1}//透明度
                onPress={() => { this.goGet('Company', this.props.company.companyId); }}>
                <View style={styles.container} >

                    <View style={styles.contTop} >
                        <Image source={
                            this.props.company.companyPicture ?
                                {uri: common_url + "uploadImg/" + this.props.company.companyPicture}
                                : require('../../../img/app/company.png')} style={styles.Img} />
                        <View style={styles.postionRight}>
                            <View style={styles.top}>
                                <Text style={styles.postionname}>{this.props.company.companyName}</Text>
                                <View style={styles.postiontype}><Text style={styles.companytypeText}>{Nature(this.props.company.companyNature)}</Text></View>
                            </View>
                            <View style={styles.middle}>
                                <Text style={styles.site}>{this.props.company.companyCity}</Text>
                                <Text style={styles.industry}>{this.fieldName(this.props.company.domains, 3)}</Text>
                            </View>
                            <View style={styles.type}>
                                {this.welfareName(this.props.company.welfares, 3)}
                            </View>
                        </View>
                    </View>

                    <View style={styles.contBottom}>
                        <View style={styles.contBottom_left}>
                            <Text style={styles.contBottom_left_text}>热门职位:</Text>
                        </View>
                        <View>
                            {this.postionName(this.props.company.postions, 2)}
                        </View>
                    </View>
                </View>
            </TouchableOpacity>
        )
    }
    fieldName(List, sl) {
        var data = {
            cont: List
        }
        var attr = '';                            //用来装公司类型
        var s = sl;
        var length = data.cont.length
        if (length <= s) {
            s = length
        }
        for (var i = 0; i < s; i++) {
            attr += data.cont[i].field.fieldName + '/';
        }
        if (attr.endsWith('/')) {
            attr = attr.substr(0, attr.length - 1);
        }
        return attr;
    }

    welfareName(List, sl) {
        var data = {
            cont: List
        }
        var arr = [];
        var s = sl;
        var length = data.cont.length
        if (length <= s) {
            s = length
        }
        for (var i = 0; i < s; i++) {
            arr.push(
                <Text key={i} style={styles.fuli}>{data.cont[i].welfareName}</Text>
            )
        }
        return arr;
    }

    postionName(List, sl) {
        var data = {
            cont: List
        }
        var arr = [];
        var s = sl;
        var length = data.cont.length
        if (length <= s) {
            s = length
        }
        for (var i = 0; i < s; i++) {
            arr.push(
                <Text key={i} style={styles.Hotpostion}>{data.cont[i].postionName}</Text>
            )
        }
        return arr;
    }

    goGet(name, id) {
        this.props.navigation.navigate(name, { useId: id });
    }


}